package svlt;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;
//import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import bean.Controlador;

public class CargarSolicitudServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private static final String PATH="c:\\temp\\";   
    
	@SuppressWarnings("unchecked")
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			String nombre= "sol"+Calendar.getInstance().getTimeInMillis() + ".xml";
			
			FileItemFactory factory = new DiskFileItemFactory();
			ServletFileUpload upload = new ServletFileUpload(factory);
			List<FileItem> items = upload.parseRequest(request);
			FileItem item = items.get(0);
			
			item.write(new File(PATH+nombre));
			Controlador.getInstance().cargarSolicitudDeCotizacion(PATH+nombre);
		} catch (Exception e) {
			System.out.println(e.toString());
		}					
}

}
